Refactor some more of the ugly b/c update logic out of updaters.inc
authorChad Horohoe <demon@users.mediawiki.org>
Sat, 17 Jul 2010 12:55:52 +0000 (12:55 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sat, 17 Jul 2010 12:55:52 +0000 (12:55 +0000)
includes/installer/Update.php
maintenance/updaters.inc

index b4e8dc8..ebe9830 100644 (file)
@@ -39,7 +39,10 @@ class Update {
                                call_user_func_array( $func, $params );
                                flush();
                        }
-                       $this->setAppliedUpdates( $version, $updates );
+                       // some updates don't get recorded :(
+                       if( $version !== 'always' ) {
+                               $this->setAppliedUpdates( $version, $updates );
+                       }
                }
        }
 
@@ -48,14 +51,15 @@ class Update {
                // style of recording our steps. Run all to be safe
                if( !$this->canUseNewUpdatelog() ) {
                        $this->updates = $this->updater->getUpdates();
-                       return;
-               }
-               foreach( $this->updater->getUpdates() as $version => $updates ) {
-                       $appliedUpdates = $this->getAppliedUpdates( $version );
-                       if( !$appliedUpdates || $appliedUpdates != $updates ) {
-                               $this->updates[ $version ] = $updates;
+               } else {
+                       foreach( $this->updater->getUpdates() as $version => $updates ) {
+                               $appliedUpdates = $this->getAppliedUpdates( $version );
+                               if( !$appliedUpdates || $appliedUpdates != $updates ) {
+                                       $this->updates[ $version ] = $updates;
+                               }
                        }
                }
+               $this->getOldGlobalUpdates();
        }
 
        protected function getAppliedUpdates( $version ) {
@@ -92,4 +96,52 @@ class Update {
                return $this->db->tableExists( 'updatelog' ) &&
                        $this->db->fieldExists( 'updatelog', 'ul_value' );
        }
+
+       /**
+        * Before 1.17, we used to handle updates via stuff like $wgUpdates,
+        * $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
+        * of this in 1.17 but we want to remain back-compatible for awhile. So
+        * load up these old global-based things into our update list. We can't
+        * version these like we do with our core updates, so they have to go
+        * in 'always'
+        */
+       private function getOldGlobalUpdates() {
+               global $wgUpdates, $wgExtNewFields, $wgExtNewTables,
+                       $wgExtModifiedFields, $wgExtNewIndexes;
+
+               if( isset( $wgUpdates[ $this->db->getType() ] ) ) {
+                       foreach( $wgUpdates[ $this->db->getType() ] as $upd ) {
+                               $this->updates['always'][] = $upd;
+                       }
+               }
+
+               foreach ( $wgExtNewTables as $tableRecord ) {
+                       $this->updates['always'][] = array(
+                               'add_table', $tableRecord[0], $tableRecord[1], true
+                       );
+               }
+
+               foreach ( $wgExtNewFields as $fieldRecord ) {
+                       if ( $fieldRecord[0] != 'user' || $doUser ) {
+                               $this->updates['always'][] = array(
+                                       'add_field', $fieldRecord[0], $fieldRecord[1],
+                                               $fieldRecord[2], true
+                               );
+                       }
+               }
+
+               foreach ( $wgExtNewIndexes as $fieldRecord ) {
+                       $this->updates['always'][] = array(
+                               'add_index', $fieldRecord[0], $fieldRecord[1],
+                                       $fieldRecord[2], true
+                       );
+               }
+
+               foreach ( $wgExtModifiedFields as $fieldRecord ) {
+                       $this->updates['always'][] = array(
+                               'modify_field', $fieldRecord[0], $fieldRecord[1],
+                                       $fieldRecord[2], true
+                       );
+               }
+       }
 }
index 33b0cd8..9535260 100644 (file)
@@ -952,41 +952,6 @@ function do_all_updates( $shared = false, $purge = true ) {
        $up = new Update( $wgDatabase );
        $up->doUpdates();
 
-       // OpenID is still using this stupid thing, or we could kill this too
-       global $wgUpdates;
-       if ( isset( $wgUpdates[$wgDBtype] ) ) {
-               foreach ( $wgUpdates[$wgDBtype] as $params ) {
-                       $func = array_shift( $params );
-                       call_user_func_array( $func, $params );
-                       flush();
-               }
-       }
-
-       // / @fixme clean up this mess too!
-       global $wgExtNewTables, $wgExtNewFields, $wgExtNewIndexes;
-       # Add missing extension tables
-       foreach ( $wgExtNewTables as $tableRecord ) {
-               add_table( $tableRecord[0], $tableRecord[1], true );
-               flush();
-       }
-       # Add missing extension fields
-       foreach ( $wgExtNewFields as $fieldRecord ) {
-               if ( $fieldRecord[0] != 'user' || $doUser ) {
-                       add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
-               }
-               flush();
-       }
-       # Add missing extension indexes
-       foreach ( $wgExtNewIndexes as $fieldRecord ) {
-               add_index( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
-               flush();
-       }
-       # Add modified extension fields
-       foreach ( $wgExtModifiedFields as $fieldRecord ) {
-               modify_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
-               flush();
-       }
-
        wfOut( "Deleting old default messages (this may take a long time!)..." );
        if ( !defined( 'MW_NO_SETUP' ) ) {
                define( 'MW_NO_SETUP', true );